import { Button } from "antd";
import React, { useState, useMemo } from "react";

const usePow = (list: number[]) => {
  return useMemo(
    () =>
      list.map(item => {
        console.log(item);
        return Math.pow(item, 2);
      }),
    [list]
  );
};

const lists = [1, 2, 3];
const UsePow: React.FC = () => {
  const [flag, setFlag] = useState<boolean>(true);
  const data = usePow(lists);

  return (
    <>
      <h5>数字：{data.toString()}</h5>
      <Button type="primary" onClick={() => setFlag(v => !v)}>
        切换
      </Button>
      <p>切换状态：{JSON.stringify(flag)}</p>
    </>
  );
};
export default UsePow;
